public OnPlayerDisconnect(playerid, reason) {	
	new Float:fpH, Float:fpA;
			
	GetPlayerHealth(playerid, fpH);
	GetPlayerArmour(playerid, fpA);
		
	if(playerData[playerid][isSpawned] && fpH > 0.0) {	
		switch(reason) {
			case 0: SendFormattedMessageToAll(C_GREY, "* %s left the server. (Timeout | %d HP left)", CPlayer::getName(playerid), floatround((fpH + fpA)));
			case 1: SendFormattedMessageToAll(C_GREY, "* %s left the server. (Leaving | %d HP left)", CPlayer::getName(playerid), floatround((fpH + fpA)));
			case 2: SendFormattedMessageToAll(C_GREY, "* %s left the server. (Penalty | %d HP left)", CPlayer::getName(playerid), floatround((fpH + fpA)));
		}
	}
	
	else {
		switch(reason) {
			case 0: SendFormattedMessageToAll(C_GREY, "* %s left the server. (Timeout)", CPlayer::getName(playerid));
			case 1: SendFormattedMessageToAll(C_GREY, "* %s left the server. (Leaving)", CPlayer::getName(playerid));
			case 2: SendFormattedMessageToAll(C_GREY, "* %s left the server. (Penalty)", CPlayer::getName(playerid));
		}
	}
	
	if(playerData[playerid][isDuel]) {
		if(playerid == duelData[iPlayerID][0]) {
			playerData[playerid][isDuel] = false;
			playerData[duelData[iPlayerID][1]][isDuel] = false;
			CDuel::EndDuel(duelData[iPlayerID][1]);
		}
		
		if(playerid == duelData[iPlayerID][1]) {
			playerData[playerid][isDuel] = false;
			playerData[duelData[iPlayerID][0]][isDuel] = false;
			CDuel::EndDuel(duelData[iPlayerID][0]);
		}
	}
	
	if(playerData[playerid][isPlaying]) {
		if(playerData[playerid][team] == TEAM_HOME) {
			gameData[iPlayingHome]--;
			gameData[iTotalHome]--;
		}
		
		if(playerData[playerid][team] == TEAM_AWAY) {
			gameData[iPlayingAway]--;
			gameData[iTotalAway]--;
		}
		
		CBase::updateRestrictions(playerid);
		CBase::CheckActivePlayers();
		playerData[playerid][isPlaying] = false;
	}
	
	// If someone spectates the player, we have to abort this.
	loop_players(i) {
		if(playerData[i][spectateId] == playerid)
			CPlayer::Unspectate(i);
	}
    
    if (playerData[playerid][isLogged]) {
        CAccount::savePlayer(playerid);
    }
	
	CPlayer::HideTextDraws(playerid);
	CPlayer::DestroyPlayerTextDraws(playerid);
	return true;
}